package com.xufei.auth.service;

import com.xufei.common.domain.user.User;
import com.xufei.user.feign.UserFeignClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class TokenService
{

    private final UserFeignClient userFeignClient;

    public TokenService(UserFeignClient userFeignClient) {
        this.userFeignClient = userFeignClient;
    }

    /**
     * 登录
     */
    public User login(String userName,String password)
    {
        // 用户名或密码为空
        if (StringUtils.isBlank(userName)||StringUtils.isBlank(password))
        {
            throw new RuntimeException("用户名或密码为空");
        }
        // 查询用户信息
        User user = userFeignClient.selectUserByUsername(userName);
        if(user==null){
            throw new RuntimeException("用户未注册");
        }
        if(!password.equals(user.getPassWord())){
            throw new RuntimeException("密码输入错误");
        }
        return user;
    }

}